function Person(name, age) {
  this.name = name
  this.age = age
}

Person.prototype.say = function() {
  return this.name + this.age
}

const toStringUtil = (type) => Object.prototype.toString.call(type)

function objectFactory(Func, ...args) {
  let obj = Object.create(Func.prototype)

  let res = Func.apply(obj, args)

  return toStringUtil(res) === "[object Object]" ? res : obj
}

let a = objectFactory(Person, 'yellres', 24)
console.log(a);
console.log(a.__proto__);

 

